from django.contrib import *
from django.contrib.auth.models import *
from django.core.urlresolvers import *
from django.http import *
from django.shortcuts import *
from .JsonResponse import JsonResponseSessionExpired

import website.settings


def login_required(f):
    def decorator(request):
        if not request.user.is_authenticated():
            return HttpResponseRedirect(website.settings.LOGIN_URL)
        return f(request)
    return decorator

def login_required_ajax(f):
    def decorator(request):
        if not request.user.is_authenticated():
            return JsonResponseSessionExpired({})
        return f(request)
    return decorator

